package com.artPreter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.artPreter.pojo.DepartContentSection;
import com.artPreter.mapper.DepartContentSectionMapper;
import com.artPreter.pojo.DepartSectionTemp;
import com.artPreter.service.IDepartContentSectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 内容栏目表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-11-19
 */
@Service
public class DepartContentSectionServiceImpl extends ServiceImpl<DepartContentSectionMapper, DepartContentSection> implements IDepartContentSectionService {

    @Override
    public void addContent(DepartSectionTemp departSectionTemp) {
        if(departSectionTemp.getContentType()!=null){
            String str = departSectionTemp.getContentType().toString();
            for (int i = 0; i < str.length(); i++) {
                String c = String.valueOf(str.charAt(i));
                DepartContentSection departContentSection = new DepartContentSection();
                String uuid = UUID.randomUUID().toString();
                // 内容uuid
                departContentSection.setContentId(uuid);
                // content_type 内容类型 1:简介类型 2:艺术家列表 3:艺术品列表 4:图片类型 5:资讯类型 6:超链接
                departContentSection.setContentType(Integer.parseInt(c));
                // index_num  板块顺序
                departContentSection.setIndexNum(i);
                // section_id  板块uuid
                departContentSection.setSectionId(departSectionTemp.getSectionId());
                // name  内容名称
                String name = "";
                switch (c){
                    case "1":
                        name= "单页";
                        break;
                    case "2":
                        name= "艺术家列表";
                        break;
                    case "3":
                        name= "艺术品列表";
                        break;
                    case "4":
                        name= "图片列表";
                        break;
                    case "5":
                        name= "资讯列表";
                        break;
                    case "6":
                        name= "超链接列表";
                        break;
                }
                departContentSection.setName(departSectionTemp.getName()+name);
                departContentSection.setDepartId(departSectionTemp.getDepartId());
                this.baseMapper.insert(departContentSection);

                // 在这里处理每个字符
                System.out.println(c);
            }
        }
    }


    @Override
    public List<DepartContentSection> getList(DepartContentSection departContentSection) {
        if(departContentSection.getDepartId()!=null&&departContentSection.getSectionId()!=null){
            LambdaQueryWrapper <DepartContentSection> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(DepartContentSection::getDepartId,departContentSection.getDepartId());
            queryWrapper.eq(DepartContentSection::getSectionId,departContentSection.getSectionId());
            return this.baseMapper.selectList(queryWrapper);
        }
        return null;
    }

    @Override
    public void edit(DepartContentSection departContentSection) {
        if(departContentSection.getId()==null){
            return;
        }
        DepartContentSection item = new DepartContentSection();
        item.setContent(departContentSection.getContent());
        item.setId(departContentSection.getId());
        this.baseMapper.updateById(item);
    }
}
